/*
 * smiley.java
 *
 * Created on 30 april 2008, 19:41
 */
package client.gui.smilies;

import client.communication.ClientCommunication;
import java.awt.Color;
import java.awt.GridLayout;
import java.util.Hashtable;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author  Liesbeth
 */
public class smileyPopup extends javax.swing.JPopupMenu {

    private Color mcDefaultBackGroundColor = new Color(240, 240, 240);
    private Color mcDefaultSelectionColor = new Color(153, 204, 255);
    private ISmileyOntvanger ouder;

    /** Creates new form smiley */
    public smileyPopup(ISmileyOntvanger ouder) {
        initComponents();
        this.ouder = ouder;
        Hashtable<String, String> smilies = ClientCommunication.getInstance().getSmilies();
        setLayout(new GridLayout(smilies.size() / 6, 7, 2, 2));
        String path = "/client/gui/smilies/images/";
        for (String s : smilies.keySet()) {
            JLabel l = new JLabel(new ImageIcon(getClass().getResource(path + smilies.get(s))));
            l.setToolTipText(s);
            l.setOpaque(true);
            l.addMouseListener(new java.awt.event.MouseAdapter() {

                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    smileyMouseClicked(evt);
                }

                public void mouseEntered(java.awt.event.MouseEvent evt) {
                    smileyMouseEntered(evt);
                }

                public void mouseExited(java.awt.event.MouseEvent evt) {
                    smileyMouseExited(evt);
                }
            });
            //l.setMargin(new java.awt.Insets(5,5,5,5));
            add(l);
        }
    }

    public void smileyMouseClicked(java.awt.event.MouseEvent evt) {
        ouder.addSmileyToTextField(((JLabel) evt.getSource()).getToolTipText());
    }

    public void smileyMouseEntered(java.awt.event.MouseEvent evt) {
        ((JLabel) evt.getSource()).setBackground(mcDefaultSelectionColor);
    }

    public void smileyMouseExited(java.awt.event.MouseEvent evt) {
        ((JLabel) evt.getSource()).setBackground(mcDefaultBackGroundColor);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
